package com.zhangzhan.gulimallproduct.app;

import com.zhangzhan.gulimallcommcon.util.PageUtils;
import com.zhangzhan.gulimallcommcon.util.R;
import com.zhangzhan.gulimallproduct.entity.SkuInfoEntity;
import com.zhangzhan.gulimallproduct.service.SkuInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;
import java.util.Map;




/**
 * sku信息
 *
 * @author zhangzhan
 * @email sunlightcs@gmail.com
 * @date 2024-06-12 16:45:44
 */
@RestController
@RequestMapping("gulimallproduct/skuinfo")
public class SkuInfoController {
    @Autowired
    private SkuInfoService skuInfoService;

    /**
     * getPrice
     */
    @RequestMapping(value = "/getPrice",method = RequestMethod.GET)
    public BigDecimal getPrice(@RequestParam("skuId") Long skuId){
        return  skuInfoService.getPrice(skuId);
    }

    /**
     * getName
     */
    @RequestMapping(value = "/getSkuName",method = RequestMethod.GET)
    //@RequiresPermissions("gulimallproduct:skuinfo:list")
    public R getSkuName(@RequestParam("skuId") Long skuId){
        String skuName = skuInfoService.getSkuName(skuId);

        return R.ok().put("data", skuName);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("gulimallproduct:skuinfo:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = skuInfoService.queryPageDetail(params);

        return R.ok().put("page", page);
    }

    /**
     * attrs
     */
    @RequestMapping(value = "/attrs/{skuId}",method = RequestMethod.GET)
    //@RequiresPermissions("gulimallproduct:skuinfo:info")
    public R skuAttrs(@PathVariable("skuId") Long skuId){
        List<String> attrs = skuInfoService.skuAttrs(skuId);

        return R.ok().put("attrs", attrs);
    }


    /**
     * 信息
     */
    @RequestMapping(value = "/info/{skuId}",method = RequestMethod.GET)
    //@RequiresPermissions("gulimallproduct:skuinfo:info")
    public R info(@PathVariable("skuId") Long skuId){
		SkuInfoEntity skuInfo = skuInfoService.getById(skuId);

        return R.ok().put("skuInfo", skuInfo);
    }

    /**
     * 信息
     */
    @RequestMapping(value = "/getInfoByIds",method = RequestMethod.POST)
    //@RequiresPermissions("gulimallproduct:skuinfo:info")
    public Map<Long,SkuInfoEntity> getInfoByIds(@RequestBody List<Long> skuIds){
        Map<Long,SkuInfoEntity> skuInfo = skuInfoService.getInfoByIds(skuIds);

        return skuInfo;
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("gulimallproduct:skuinfo:save")
    public R save(@RequestBody SkuInfoEntity skuInfo){
		skuInfoService.save(skuInfo);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("gulimallproduct:skuinfo:update")
    public R update(@RequestBody SkuInfoEntity skuInfo){
		skuInfoService.updateById(skuInfo);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("gulimallproduct:skuinfo:delete")
    public R delete(@RequestBody Long[] skuIds){
		skuInfoService.removeByIds(Arrays.asList(skuIds));

        return R.ok();
    }

}
